package src.main.java.org.collection.game;

import src.main.java.org.generic.genericsMethods.Car;

import java.util.*;

public class Room {
    //需要有一张牌
    private List<Card> allCards = new ArrayList<>();

    public Room(){
        //1.做出54张牌，存入到allCards中
        //点数：个数确定，类型确定
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        //花色，个数确定，类型确定
        String[] color = {"♥","♠","♣","♦"};
        int size = 0 ;//表示每张牌大小
        //组合点数花色
        for (String number : numbers) {
            size++;
            for (String s : color) {
                //得到一张牌
                Card c = new Card(number,s,size);
                allCards.add(c);
            }
        }
        //单独存入大小王
        Card c1 = new Card("","小王",++size);
        Card c2 = new Card("","大王",++size);
        Collections.addAll(allCards,c1,c2);
        System.out.println("这是一幅新牌:"+allCards);
    }
    public void start(){
        Collections.shuffle(allCards);
        System.out.println("洗牌后："+allCards);
        //发牌，
        List<Card> zhangsan = new ArrayList<>();
        List<Card> lisi  = new ArrayList<>();
        List<Card> wangwu = new ArrayList<>();
        for (int i = 0; i < allCards.size(); i++) {
            Card c = allCards.get(i);
            if(i%3==0){
                zhangsan.add(c);
            }else if(i%3==1){
                lisi.add(c);
            } else if (i%3==2) {
                wangwu.add(c);
            }
        }
        //3.对三个玩家牌排序
        sortCards(zhangsan);
        sortCards(lisi);
        sortCards(wangwu);
        //4.看牌
        System.out.println("zhangsan:"+zhangsan);
        System.out.println("lisi:"+lisi);
        System.out.println("wangwu:"+wangwu);
        List<Card> lastThreeCards = allCards.subList(allCards.size() - 3, allCards.size());
        System.out.println("底牌："+lastThreeCards);
        wangwu.addAll(lastThreeCards);
        System.out.println("王五抢到地主："+wangwu);
    }

    private void sortCards(List<Card> cards) {
        Collections.sort(cards, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getSize()-o2.getSize();
            }
        });
    }
}
